package cn.slahser.utils;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.Hashtable;
import java.util.Vector;

import cn.slahser.activity.MainActivity;
import cn.slahser.serverEntity.Message;
import cn.slahser.serverEntity.ShuoExt;

public class AcionClientTCP extends Thread {
	static Socket socket = null;
	// 主界面传过来
	public static MainActivity action = null;

	public void run() {
		try {
			Socket socket = new Socket(SlahserMetaData.IP,
					SlahserMetaData.ACTIONPORT);
			ObjectOutputStream oout = new ObjectOutputStream(
					socket.getOutputStream());
			ObjectInputStream oin = new ObjectInputStream(
					socket.getInputStream());
			Message message = new Message();
			Hashtable<String, Object> table = new Hashtable<String, Object>();
			// 此时loginclienttcp已经执行过，全局的userid已经有值
			table.put("userid", SlahserMetaData.userid);
			// 设置传递信息
			message.setValue(table);
			oout.writeObject(message);
			oout.flush();
			while (true) {
				oin.readObject();
				Vector<ShuoExt> vv = LoginClientTCP.getData();
				if (action != null) {
					action.view2 = vv;
					android.os.Message msg1 = new android.os.Message();
					action.handler.sendMessage(msg1);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public static void closeClient() throws Exception {
		try {
			socket.close();
		} catch (Exception ex) {
			throw ex;
		}
	}

}
